/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-22 13:34:02
 * @LastEditTime: 2019-10-05 12:30:21
 * @LastEditors: Please set LastEditors
 */
import Vue from 'vue'
import Router from 'vue-router'
import Index from './views/index'
import Register from './views/Register.vue'
import Login from './views/login.vue'
import Home from './views/Home.vue'
import InfoShow from './views/InfoShow'
import FoundList from './views/FoundList'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path:'/',
      redirect:'/index'
    },{
      path:'/index',
      name:'index',
      component:Index,
      children:[
        {path:'',component:Home},
        {path:'/home',name:'home',component:Home},
        {path:'/infoshow',name:"infoshow",component:InfoShow},
        {path:'/foundlist',name:"foundlist",component:FoundList}
      ]
    },{
      path:'/register',
      name:'register',
      component:Register
    },{ 
      path:'*',
      name:'/404',
      component(){
        return import('./views/404.vue')
      }
    },{
      name:'login',
      path:'/login',
      component:Login
    }
  ]
})

// 路由守卫
router.beforeEach((to,from,next)=>{
  const isLogin = localStorage.eleToken?true:false
  if(to.path == '/login' || to.path == '/register'){
    next()
  }else{
    isLogin ? next() : next('/login')
  }
})

export default router